package com.smmisia.article.controller;

import com.smmisia.article.request.MessageRequest;
import com.smmisia.article.response.socket.GroupMessageResponse;
import com.smmisia.article.response.socket.MessageResponse;
import com.smmisia.article.service.MessageService;
import com.smmisia.common.Result.Result;
import com.smmisia.common.request.feign.request.FeignMessageGroupRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/chat")
@Slf4j
@Tag(name = "聊天室")
public class ChatController {

    @Autowired
    private MessageService messageService;

    /**
     * 发送消息(点对点)
     * @return
     */
    @PostMapping("/send")
    @Operation(summary = "发送消息")
    public Result send(@Valid @RequestBody MessageRequest request) {
        return messageService.send(request);
    }

    /**
     * 发送群消息
     * @param request
     * @return
     */
    @PostMapping("/seedGroup")
    @Operation(summary = "发送群消息")
    public Result seedGroup(@Valid @RequestBody FeignMessageGroupRequest request) {
        return messageService.sendGroup(request);
    }

    /**
     * 获取消息(点对点)
     * @param sendId
     * @return
     */
    @GetMapping("/message")
    @Operation(summary = "获取消息")
    public Result<MessageResponse> getMessage(@RequestParam Integer sendId){
        return messageService.getMessage(sendId);
    }

    /**
     * 获取群消息
     * @param groupId
     * @return
     */
    @GetMapping("/groupMessage")
    @Operation(summary = "获取群消息")
    public Result<GroupMessageResponse> getGroupMessage(@RequestParam @NotEmpty(message = "群组id不能为空") Integer groupId){
        return messageService.getGroupMessage(groupId);
    }

}